package com.ruoyi.api.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.tools.enums.DeviceTypeEnum;
import com.ruoyi.common.tools.utils.DateUtils;
import com.ruoyi.erecord.locus.domain.bo.LocusBo;
import com.ruoyi.erecord.locus.domain.vo.LocusVo;
import com.ruoyi.erecord.locus.service.ILocusService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 人员和车辆轨迹数据统计汇总
 *
 * @author cc
 * @date 2023-04-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/stat/locus")
public class LocusApiStatController extends BaseController {
    private final ILocusService iLocusService;

    /**
     * 根据车辆ID查询车辆轨迹
     *
     * @param cid  车辆ID
     * @return 返回车辆轨迹
     */
    @GetMapping("/car/{cid}")
    public R<List<LocusVo>> listCar(@PathVariable String cid) {
        LocusBo bo = new LocusBo();
        bo.setDeviceType(DeviceTypeEnum.CAR.getCode());
        bo.setDeviceOriginalId(cid);
        String beginGpsTime = DateUtils.getCurrDate();
        String endGpsTime = DateUtils.getNextDate(beginGpsTime, 1);
        bo.getParams().put("beginGpsTime", beginGpsTime);
        bo.getParams().put("endGpsTime", endGpsTime);
        return R.ok(iLocusService.queryList(bo));
    }

    /**
     * 根据车辆ID查询车辆轨迹
     *
     * @param uid 用户ID
     * @return 用户轨迹
     */
    @GetMapping("/user/{uid}")
    public R<List<LocusVo>> listUser(@PathVariable String uid) {
        LocusBo bo = new LocusBo();
        bo.setDeviceType(DeviceTypeEnum.USER.getCode());
        bo.setDeviceOriginalId(uid);
        String beginGpsTime = DateUtils.getCurrDate();
        String endGpsTime = DateUtils.getNextDate(beginGpsTime, 1);
        bo.getParams().put("beginGpsTime", beginGpsTime);
        bo.getParams().put("endGpsTime", endGpsTime);
        return R.ok(iLocusService.queryList(bo));
    }
}
